﻿using DataServer.ApplicationLib.Entities;

namespace Config.WebApi.Contracts
{
    public class ConfigColMetaData
    {
        private static IList<ConfigColMetaDataEntity> configColMetaDataEntities = new List<ConfigColMetaDataEntity>();

        static ConfigColMetaData()
        {
            RegisterConfigColMetaData();
        }

        private static void RegisterConfigColMetaData()
        {
            var propertities = typeof(ConfigDataEntity).GetProperties();
            foreach (var propertity in propertities)
            {
                if (propertity.Name.StartsWith("Varchar"))
                {
                    configColMetaDataEntities.Add(new ConfigColMetaDataEntity
                    {
                        ColumnCode = propertity.Name,
                        ColumnName = propertity.Name,
                        DataType = DataType.ColumnVarchar
                    });
                }
                else if (propertity.Name.StartsWith("Number"))
                {
                    configColMetaDataEntities.Add(new ConfigColMetaDataEntity
                    {
                        ColumnCode = propertity.Name,
                        ColumnName = propertity.Name,
                        DataType = DataType.ColumnNumber
                    });
                }
            }
        }

        public static IList<ConfigColMetaDataEntity> GetConfigColMetaData()
        {
            return configColMetaDataEntities;
        }
    }

    public class ConfigColMetaDataEntity
    {
        public string? DataType { get; set; }

        public string? ColumnCode { get; set; }

        public string? ColumnName { get; set; }
    }
}